
/*-----------------------------------------------*
Name: Haqdarshak Pilot Intervention-Analysis
Date Created: 30 July, 2018
Date Last Modified: 28 April, 2021
Created by: Aaron Berman and modified by Daniela Paz and Saumya Mathur on Nov.13/2020 
Uses Data: screening_takeup
Creates Data: Latex Tables
Description: Creates tables for the main analysis on screening take-up
*-------------------------------------------------*/



*..................................................
**Install user-written commands
foreach package in mdesc nmissing veracrypt {
     capture which `package'
	 if _rc==111 ssc install `package'
}
*..................................................
clear all
set more off
version 12.0
cap log close
pause off



//open log 
*cd "$logs"
*log using "tables_1_2.smcl", replace


*Tables 1 and 2: Screening Take-up Regressions

	use "$intermediate_data/screening_takeup", clear

	//regressions
	eststo clear 
	forv i = 1/4 {
		local condition: word `i' of "1" "1" "hh_num_child > 0" "hh_num_disabled > 0"
		local depvar: word `i' of "takeup_dummy_use" "morethan1_takeup" "hh_child_screened_dummy_use" "hh_disabled_screened"
		eststo: reg `depvar' treat_100 treat_50 d_stratum_* any_warning if `condition', robust 
		test treat_100=treat_50
		estadd scalar pval `r(p)'
		summ `depvar' if `condition' & treat_0 == 1 
		estadd scalar control_mean `r(mean)'
	}
	
	//output to latex 
	cd "$Main"

	#delimit ;
	esttab *
		using "Table_3.tex", booktabs label se
		drop(_cons d_stratum_* any_warning)
		b(%12.3f)
		se(%12.3f)
		starlevels(* .10 ** .05 *** .01)
		mlabels("Any Screening in HH" ">1 Screening in HH" "Child Screened in HH" "Disabled Member Screened")
		varlab(treat_100 "Free Screening" treat_50 "Half-Priced Screening")
		scalars("control_mean Mean at Full Price Screening" "pval /(p/)-value (Free = Half-Priced)")
		nonotes
		fragment
		r2
		replace;

	#delimit cr 

	//APPENDIX TABLE regressions for Child & Disabled screenings
	eststo clear 
	forv i = 1/2 {
		local depvar: word `i' of "hh_child_screened_dummy_use" "hh_disabled_screened"
		eststo: reg `depvar' treat_100 treat_50 d_stratum_* any_warning, robust 
		test treat_100=treat_50
		estadd scalar pval `r(p)'
		summ `depvar' if treat_0 == 1 
		estadd scalar control_mean `r(mean)'
	}
	
	//output to latex 
	cd "$Appe"

	#delimit ;
	esttab *
		using "Table_A8.tex", booktabs label se
		drop(_cons d_stratum_* any_warning)
		b(%12.3f)
		se(%12.3f)
		starlevels(* .10 ** .05 *** .01)
		mlabels("Child Screened in HH" "Disabled Member Screened")
		varlab(treat_100 "Free Screening" treat_50 "Half-Priced Screening")
		scalars("control_mean Mean at Full Price Screening" "pval /(p/)-value (Free = Half-Priced)")
		nonotes
		fragment
		r2
		replace;

	#delimit cr 



	*Table 2: Who takes up screening?
	//change income dummy to missing if missing annual income 
	replace above_48000 = . if missing(enter_annual_income)

	//dummies for baseline eligibility of schemes 
	egen num_baseline_eligible = rowtotal(elig_*)
	gen elig_nopost_nopension = (elig_sukanya == 1 | elig_awas_yojana == 1 | elig_oldage_pension == 1 | elig_widow_pension == 1)
	gen elig_oldage_widow = (elig_oldage_pension == 1 | elig_widow_pension == 1)


	//generate interactions for heterogeneity
	foreach x of varlist any_disability_hh above_48000 member_male_1 caste_general applied_for_govt_scheme num_disruptions num_baseline_eligible elig_nopost_nopension elig_oldage_widow {
		gen `x'_50i = `x' * treat_50
		gen `x'_100i = `x' * treat_100
	}

	//label variables appropriately
	label var any_disability_hh "At Least 1 Household Member Disabled"
	label var above_48000 "Annual Income $/geq$ Rs. 48,000"
	label var member_male_1 "HH Respondent is Male"
	label var caste_general "General Caste"
	label var applied_for_govt_scheme "Applied for Gov't. Scheme in Last 2 Yrs."
	label var num_disruptions "/# of Economic Disruptions in Last Yr."
	label var num_baseline_eligible "/# of Eligible Schemes in HH"
	label var elig_nopost_nopension "Eligible for Top Scheme (Outside Savings and Atal)"
	label var elig_oldage_widow "Eligible for Old Age or Widow Pension"

	forv i = 1/9 {
		local depvar: word `i' of "any_disability_hh" "above_48000" "member_male_1" "caste_general" "applied_for_govt_scheme" "num_disruptions" "num_baseline_eligible" "elig_nopost_nopension" "elig_oldage_widow"
		local label: word `i' of "At Least 1 Household Member Disabled" "Annual Income $/geq$ Rs. 48,000" "HH Respondent is Male" "General Caste" "Applied for Gov't. Scheme in Last 2 Yrs." "/# of Economic Disruptions in Last Yr." ///
						"/# of Eligible Schemes in HH" "Eligible for Top Scheme (Outside Savings and Atal)" "Eligible for Old Age or Widow Pension"
		label var `depvar'_50i "`label' $/times$ Rs. 40 Screening"
		label var `depvar'_100i "`label' $/times$ Rs. 0 Screening"
	}

	//FIRST SET OF TABLES: Any take-up 
	//generate holder variable 
	gen holder = .
	gen holder_100i = .
	gen holder_50i = .
	label var holder "Variable" 
	label var holder_100i "Variable $/times$ Free Screening"
	label var holder_50i "Variable $/times$ Half-Priced Screening"

	//regressions
	eststo clear 
	foreach hetvar of varlist above_48000 caste_general applied_for_govt_scheme num_disruptions {
		replace holder = `hetvar'
		replace holder_100i = `hetvar'_100i
		replace holder_50i = `hetvar'_50i
		eststo: reg takeup_dummy_use treat_100 treat_50 holder holder_100i holder_50i d_stratum_* any_warning, robust //updated 9/25: no control for HH size, updated takeup variable. 9/30 added warning
		summ takeup_dummy_use if treat_0 == 1
		estadd scalar control_mean `r(mean)'
	}
	
	//output to latex 
	cd "$Main"

	#delimit ;
	esttab *
		using "Table_4.tex", booktabs label se
		drop(_cons treat_100 treat_50 d_stratum_* any_warning)
		b(%12.3f)
		se(%12.3f)
		starlevels(* .10 ** .05 *** .01)
		mlabels("Annual Income $/geq$ Rs. 48,000" "General Caste" "Applied for Gov't. Scheme in Last 2 Yrs." "/# of Economic Disruptions in Last Yr.")
		scalars("control_mean Mean at Full Price Screening")
		nonotes
		fragment
		r2
		replace;

	#delimit cr 


	//Added 12/12: Additional regressions to test heterogeneity 
	eststo clear 
	foreach hetvar of varlist num_baseline_eligible elig_nopost_nopension elig_oldage_widow {
		replace holder = `hetvar'
		replace holder_100i = `hetvar'_100i
		replace holder_50i = `hetvar'_50i
		eststo: reg takeup_dummy_use treat_100 treat_50 holder holder_100i holder_50i d_stratum_* any_warning, robust //updated 9/25: no control for HH size, updated takeup variable. 9/30 added warning
		summ takeup_dummy_use if treat_0 == 1
		estadd scalar control_mean `r(mean)'
	}
	
	//output to latex 
	cd "$latex"

	#delimit ;
	esttab *
		using "Additional Screening Heterogeneity.tex", booktabs label se
		drop(_cons treat_100 treat_50 d_stratum_* any_warning)
		b(%12.3f)
		se(%12.3f)
		starlevels(* .10 ** .05 *** .01)
		mlabels("/# of Eligible Schemes in HH" "Eligible for Top Scheme (Outside Savings and Atal)" "Eligible for Old Age or Widow Pension")
		scalars("control_mean Mean at Full Price Screening")
		nonotes
		fragment
		r2
		replace;

	#delimit cr 	

	*pause

	//output tabulation of different het variables 
	label define elig_yesno 1 "Yes" 0 "No"
	label values elig_nopost_nopension elig_yesno
	label values elig_oldage_widow elig_yesno

	foreach x of varlist num_baseline_eligible elig_nopost_nopension elig_oldage_widow {
		eststo clear
		estpost tab `x' 
		cd "$latex"
		#delimit ;
		esttab using "`x' tabulation.tex",
			label booktabs
			mlabels("Number of HHs")
			varlabels(`e(labels)')
			varwidth(50)
			nonumbers 
			drop(Total)
			nonotes
			nogaps
			fragment
			replace;
		#delimit cr
	}



